<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@include file="common/header.jsp"%>
<style>
	.in1{
	width: 40%;
    border: 1px solid grey
	
	}

	#in2{
	width: 40%;
	
	}
	#in3{
	width: 40%;
	
	}
	#in4{
	width: 40%;
	
	}
	#backbtn{
	width: 100px;
    height: 33px;
    background: gray;
    color: white;
    }
    #btn1{
    width: 100px;
    }
    
    #btn2{
    width: 100px;
    }
    .upload-img{position:relative;}
		.upload-img input{opacity: 0;border: 1px solid red;width: 177px;height: 164px;position: absolute;z-index: 1;}
</style>

        <!-- /. NAV SIDE  -->
	<div id="page-wrapper">
		<div id="page-inner">
			

			<!-- /.col-lg-6 (nested) -->
			<div class="am-tabs-bd">
				<div class="am-tab-panel am-fade am-in am-active" id="tab1">
					<div class="col-lg-12">
						<h4></h4>
						<form role="form" method="post" enctype="multipart/form-data"
							action="${pageContext.request.contextPath }/provider/modifysave">

							<input type="hidden" name="id" value="${product.id }" /> <input
								type="hidden" name="createBy" value="${product.createBy }" />
							<div class="form-group input-group">
								<span class="input-group-addon">*商品名字：</span> <input type="text"
									id="productName" required="required" class="form-control"
									name="p_Name" value="${product.p_Name }" /> <span
									style="color:red"></span>
							</div>
							<div class="form-group input-group">
								<span class="input-group-addon">*所属地区：</span> <input type="text"
									required="required" class="form-control" name="area"
									value="${product.area }">
							</div>
							<div class="form-group input-group">
								<span class="input-group-addon">*联系人：&nbsp;&nbsp;&nbsp;&nbsp;</span>
								<input type="text" class="form-control" name="contact"
									value="${product.contact }" required="required">
							</div>
							<div class="form-group input-group">
								<span class="input-group-addon">*联系电话：</span> <input type="text"
									class="form-control" name="phone" value="${product.phone }"
									required="required">
							</div>
							<div class="form-group input-group">
								<span class="input-group-addon">*详细地址：</span> <input type="text"
									class="form-control" id="productaddress" name="address"
									value="${product.address }" required="required">
							</div>
							<div class="form-group">
								<label for="desc">大概简介：</label>
								<textarea rows="3" cols="80" class="form-control" name="desc"
									required="required">${product.desc }</textarea>
							</div>
							<br />
							<div class="form-group input-group" id="in2">
								<span class="input-group-addon">单价：￥</span> <input type="text"
									class="form-control" name="price" value="${product.price }"
									required="required"> <span class="input-group-addon">元</span>
							</div>
							<br />
							<label>主题照片：</label>
								<div class="upload-img">
								    <input id="img-upload" type="file" name="attachs" accept="image/*">
								    <img id="img-show" src="/pic/${product.org_PicPath}" class="img-polaroid" width="170" height="170" alt="上传图片" title="上传图片">  
								</div>
							<br/>
							<div class="row"><label>简介照片：</label></div>
							<div class="row">
							
								<div class="col-md-4">
									<div class="upload-img">
								    <input id="img-upload1" type="file" name="attachs" accept="image/*">
								    <img id="img-show1" src="/pic/${product.pic_Path_1}" class="img-polaroid" width="170" height="170" alt="上传图片" title="上传图片">  
								</div>
								</div>
								<div class="col-md-4">
								<span class="upload-img">
								    <input id="img-upload2" type="file" name="attachs" accept="image/*">
								    <img id="img-show2" src="/pic/${product.pic_Path_2}" class="img-polaroid" width="170" height="170" alt="上传图片" title="上传图片">  
								</span>
								</div>
								<div class="col-md-4">
								<span class="upload-img">
								    <input id="img-upload3" type="file" name="attachs" accept="image/*">
								    <img id="img-show3" src="/pic/${product.pic_Path_3}" class="img-polaroid" width="170" height="170" alt="上传图片" title="上传图片">  
								</span>
								</div><!--img end -->
							
							</div>
							<div class="form-group">
								<!-- <span class="input-group-addon">所属分类：</span> -->
								<label>所属分类：</label> <select class="form-control" name="p_type"
									id="in3">
									<c:if test="${product.p_type==1 }">
										<option value="1" selected="selected">景点</option>
										<option value="2">酒店</option>
										<option value="3">餐饮</option>
									</c:if>
									<c:if test="${product.p_type==2 }">
										<option value="1">景点</option>
										<option value="2" selected="selected">酒店</option>
										<option value="3">餐饮</option>
									</c:if>
									<c:if test="${product.p_type==3 }">
										<option value="1">景点</option>
										<option value="2">酒店</option>
										<option value="3" selected="selected">餐饮</option>
									</c:if>



								</select>
							</div>
							<div class="form-group">
								<!-- <span class="input-group-addon">所属分类：</span> -->
								<label>商品状态：</label> <select class="form-control" name="status"
									id="in4">
									<c:if test="${product.status==0 }">
										<option value="0" selected="selected">下架</option>
										<option value="1">上架</option>
									</c:if>
									<c:if test="${product.status==1 }">
										<option value="0">下架</option>
										<option value="1" selected="selected">上架</option>
									</c:if>


								</select>
							</div>

							<br /> <br /> <br /> <br />


							<div class="col-md-2 col-md-push-2">
								<button type="submit" class="btn btn-danger" id="btn1">提交</button>
							</div>
							<div class="col-md-2 col-md-push-4">
								<button type="reset" class="btn btn-primary" id="btn2">重置</button>
							</div>
							<div class="col-md-2 col-md-push-6">
								<input type="button" id="backbtn" value="返回" />
							</div>


						</form>
					</div>
				</div>
			</div><!-- /.col-lg-6 (nested) -->
		</div>

	</div>

<footer>
	
</footer>


    <!-- JS Scripts-->
    <!-- jQuery Js -->
    <%@include file="common/js.jsp"%>
    <script>
     
    		$('#backbtn').on("click", function() {
    			history.back(-1);
    		});
    		
    		$('#productName').on("change",function(){
    			var pname = $('#productName').val();
    			var paddress = $("#productaddress").val();
    			isExist();
    		});
    		
    		$('#productaddress').on("change",function(){
    			var pname = $('#productName').val();
    			var paddress = $("#productaddress").val();
    			isExist();
    			});
    		
    		
    		 function isExist(){
    			var pname = $('#productName').val();
    			var paddress = $("#productaddress").val();
    			
    			$.ajax({
    				url : "/Trip/provider/isExist",
    				data : {
    					pname : pname,
    					address : paddress
    				},
    				dataType : "json",
    				success : function(data) {
    					if (data == "noexist") { //如果已经存在，就返回提示信息
    						$('#productName').next().html("")
    					} else {
    						$('#productName').next().html("该商品已存在，请重新填入")
    						$('#productName').val("");
    						$("#productaddress").val("");
    					}
    				},
    				error : function(data) {
    					alert("验证失败");
    				}
    			});
    		}
    		$('#img-upload').change(function(e){
        var input = $("#img-upload");
        var file = input[0].files[0];//获取input上传的文件
        if(!file.name){
            alert("未选择图片");
        }else{
            //高版本浏览器对文件上传路径进行了安全处理，无法直接通过获取input的value进行访问，故转化为获取图片的url进行安全访问
            var url = window.URL.createObjectURL(file);//将上传的文件转化为url
            $("#img-show").attr('src', url);//更新img的src属性
        };
    });
    $('#img-upload1').change(function(e){
        var input = $("#img-upload1");
        var file = input[0].files[0];//获取input上传的文件
        if(!file.name){
            alert("未选择图片");
        }else{
            //高版本浏览器对文件上传路径进行了安全处理，无法直接通过获取input的value进行访问，故转化为获取图片的url进行安全访问
            var url = window.URL.createObjectURL(file);//将上传的文件转化为url
            $("#img-show1").attr('src', url);//更新img的src属性
        };
    });
    $('#img-upload2').change(function(e){
        var input = $("#img-upload2");
        var file = input[0].files[0];//获取input上传的文件
        if(!file.name){
            alert("未选择图片");
        }else{
            //高版本浏览器对文件上传路径进行了安全处理，无法直接通过获取input的value进行访问，故转化为获取图片的url进行安全访问
            var url = window.URL.createObjectURL(file);//将上传的文件转化为url
            $("#img-show2").attr('src', url);//更新img的src属性
        };
    });
    $('#img-upload3').change(function(e){
        var input = $("#img-upload3");
        var file = input[0].files[0];//获取input上传的文件
        if(!file.name){
            alert("未选择图片");
        }else{
            //高版本浏览器对文件上传路径进行了安全处理，无法直接通过获取input的value进行访问，故转化为获取图片的url进行安全访问
            var url = window.URL.createObjectURL(file);//将上传的文件转化为url
            $("#img-show3").attr('src', url);//更新img的src属性
        };
    });
    		
    </script>
    
   
</body>
</html>
